/* 
 * Copyright (C) 2012 Martin Řehánek <Martin.Rehanek at mzk.cz>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

goog.provide('kramerius.audio.ui.PlayNextButton');

goog.require('kramerius.audio.ui.Button');
goog.require('kramerius.audio.debug_utils');
goog.require('goog.ui.Component');
goog.require('goog.ui.Control');

/** @const */ 
var PLAY_NEXT = 'btnPlayNext';

/**
 * @constructor 
 * @param {Element} container Element containing this button.
 * @param {kramerius.audio.Controller} controller Controller of the audio player.
 * @param {boolean} loggingEnabled whether logging should be enabled (for debugging)
 */
kramerius.audio.ui.PlayNextButton = function(container, controller, loggingEnabled){
    kramerius.audio.ui.Button.call(this, container, controller);
    /** @private */
    this.controller_.setPlayNextButton(this);
    /** @private */
    this.btnControl_ = this.initializeControl_();
    /** @private */
    this.loggingEnabled_ = loggingEnabled;
    /** @private */
    this.buttonEnabled_ = false;
    this.setContainerClass_(PLAY_NEXT);
};
goog.inherits(kramerius.audio.ui.PlayNextButton, kramerius.audio.ui.Button);

/** @private */
kramerius.audio.ui.PlayNextButton.prototype.initializeControl_ = function(){
    var control = new goog.ui.Control();
    control.setDispatchTransitionEvents(goog.ui.Component.State.ACTION, true);
    var controller = this.controller_;
    var button = this;
    goog.events.listen(control, goog.ui.Component.EventType.ACTION,
        function (e) {
            if (button.isEnabled()){
                button.log_("playing next track");
                controller.playNextTrack();
            }else{
                button.log_("WARNIG: clicked when inactive");
            }
        });
    //  kramerius.audio.utils.appendDebugListeners(button, "play next button");
    new goog.ui.Tooltip(this.container_, "přehrát následující skladbu");
    control.decorate(this.container_);
    return control;
};

kramerius.audio.ui.PlayNextButton.prototype.enable = function(){
    this.buttonEnabled_ = true;
};

kramerius.audio.ui.PlayNextButton.prototype.disable = function(){
    this.buttonEnabled_ = false;
};

kramerius.audio.ui.PlayNextButton.prototype.isEnabled = function(){
    return !!this.buttonEnabled_;
}

/** @private */
kramerius.audio.ui.PlayNextButton.prototype.log_ = function(text){
    if (this.loggingEnabled_){
        console.log("PLAY NEXT button: " + text);
    }
}

